package com.neu.wangxiaoyang.servlet;

import com.neu.wangxiaoyang.service.SBLoginService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.*;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;
import java.util.Map;

@WebServlet(name = "SBLoginServlet", urlPatterns = {"/SBLoginServlet.do"})
public class SBLoginServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String no=request.getParameter("no");
        String pwd=request.getParameter("pwd");
        String stu_cookie=request.getParameter("stu_cookies");
        SBLoginService ss=new SBLoginService();
        List<Map<String ,Object>>item=ss.SBLogin(no,pwd);
        boolean flag=false;
        if(item.size()>0){
            if ("1".equals(stu_cookie)) {
                Cookie cookie = new Cookie("stuBoss_info", no + ":" + pwd);
                cookie.setMaxAge(60 * 60 * 24 * 7);
                response.addCookie(cookie);
            }
            HttpSession session=request.getSession();
            session.setAttribute("stubs",item);
            flag=true;
        }
        PrintWriter out=response.getWriter();
        out.print(flag);
        out.close();
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }
}
